<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加知识点</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/laypage.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script src="/js/jquery.validation/1.14.0/messages_zh.min.js"></script>
    <style>
        input.error {
            border: 1px solid #FF0000;
        }
    </style>
</head>
<body>
<div class="container">
    <form id="addPointForm">
        <br/>
        <div class="form-group">
            <label for="lib_name">课程名：</label>
            <select id="select1">
                <option>---请选择---</option>
             <#list  courses as courses>
                <option value="${courses.course_id}">${courses.course_name}</option>
            </#list>
            </select>
        </div>
        <div class="form-group">
            <label for="point_name">知识点：</label>
            <input type="text" class="form-control" id="point_name" name="point_name" placeholder="题库描述">
            <input type="hidden" value="1" id="teacher_id">
        </div>
        <div class="form-group">
            <label for="lib_name">题库：</label>
            <select id="select2">
                <option>---请选择---</option>
            <#list  libs as libs>
                <option value="${libs.lib_id}">${libs.lib_name}</option>
            </#list>
            </select>
        </div>
        <div class="form-group">
            <button type="button" id="saveBtn" class="btn btn-success">提交</button>
            <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
        </div>
    </form>
</div>
<script>
    var addPoint = function () {
        if(!check().form()){
            return
        }
        $.ajax({
            type:'GET',
            dataType:'json',
            url:'/point/addPoint.do',
            data:{
                "course.course_id":$("#select1 option:selected").val(),
                "point_name":$("#point_name").val(),
                "lib.lib_id":$("#select2 option:selected").val(),
                "teacher.teacher_id":$("#teacher_id").val()/*教师id不固定*/
            },
            success:function () {
                $("#cancelBtn").click();
            }
        });
    }
      $("#saveBtn").click(function () {
        addPoint();
    });
    $("#cancelBtn").click(function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.getPointList();
        parent.layer.close(index);
    });
    //校验操作
    function check() {
        return $('#addPointForm').validate({
            rules:{
                point_name:{
                    required:true
                },
            },
            messages:{
                point_name:{
                    required:""
                },
            }
        });
    }
</script>
</body>
</html>